package com.hbxx.lotteryapp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbxx.lotteryapp.commons.Result;
import com.hbxx.lotteryapp.commons.TokenService;
import com.hbxx.lotteryapp.entity.LoginUser;
import com.hbxx.lotteryapp.entity.CashRecord;
import com.hbxx.lotteryapp.mapper.CashRecordMapper;
import com.hbxx.lotteryapp.service.ICashRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  提现记录服务实现类
 * </p>
 *
 * @author Tonny
 * @since 2022-06-07
 */
@Service
public class CashRecordServiceImpl extends ServiceImpl<CashRecordMapper, CashRecord> implements ICashRecordService {
    @Resource
    TokenService tokenService;
    @Resource
    private CashRecordMapper cashRecordMapper;

    /**
     * 提现记录分页查询
     * @param pageNum
     * @param pageSize
     * @param request
     * @return
     */
    @Override
    public Result queryPage(Integer pageNum, Integer pageSize, HttpServletRequest request) {
        LoginUser loginUser = tokenService.getLoginUser(request);
        String openId = loginUser.getOpenId();
        QueryWrapper<CashRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("open_id",openId).orderByDesc("recharge_time");
        Page<CashRecord> cashRecordPage = new Page<>(pageNum, pageSize);
        Page<CashRecord> recordPage = cashRecordMapper.selectPage(cashRecordPage, queryWrapper);
        return Result.SUCCESS(recordPage);

    }
}
